Skip to content

fix: use os.homedir() for models cache path on Windows - #886

Open
tusharui wants to merge 3 commits into
Nano-Collective:mainfrom
tusharui:fix/windows-models-cache-path
Open

fix: use os.homedir() for models cache path on Windows#886
tusharui wants to merge 3 commits into
Nano-Collective:mainfrom
tusharui:fix/windows-models-cache-path

Conversation

@tusharui

Copy link
Copy Markdown

Problem

On Windows, process.env.HOME is undefined. The models cache fallback path uses process.env.HOME || '~', which resolves to the literal string ~/.cache — not the user's actual home directory. This causes:

  • Cache writes to fail silently (caught and logged as a warning)
  • Models re-fetched from the network on every launch
  • A stray ~ folder created in the current working directory

Fix

Replace process.env.HOME || '~' with os.homedir() in source/models/models-cache.ts. os.homedir() returns the correct home directory on all platforms:

  • Windows: C:\Users\username
  • macOS: /Users/username
  • Linux: /home/username

Testing

All 9 existing tests in models-cache.spec.ts pass.

process.env.HOME is undefined on Windows, causing path.join('~', '.cache')
to create a literal ~ directory. Use os.homedir() which resolves correctly
on all platforms.
@akramcodez

Copy link
Copy Markdown
Collaborator

@tusharui Thanks for the fix! One small process request for future contributions: please create an issue first for any new bugs/features, then ask to be assigned before starting the implementation. This helps us keep ownership and scope clear.

For the additional issues you found here, please open separate issues for them first, and then feel free to pick them up once assigned:

  • Duplicate cache-path logic in scripts/fetch-models.js
  • Dead macOS branch in DEFAULT_CACHE_DIR

For this PR, please add the Windows-specific regression test mentioned above and rerun the tests. Everything else looks good!

…ests

- Fix scripts/fetch-models.js to use os.homedir() instead of
  process.env.HOME || '~' which produces a literal ~ directory on Windows
- Add regression tests that verify the old pattern produces a literal ~
  while os.homedir() resolves the real home directory

@akramcodez akramcodez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crazy work @tusharui, LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants